package cn.howxu.yichen_ovo.client.render.entity;

import cn.howxu.yichen_ovo.Res;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.resources.TextureAtlasHolder;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.client.event.RegisterClientReloadListenersEvent;
import cn.howxu.yichen_ovo.registry.api.PaintingType;
import cn.howxu.yichen_ovo.registry.PaintingTypeRegistry;

import java.util.Objects;

public class PaintingTextureManager extends TextureAtlasHolder {
	public static final ResourceLocation LOCATION_DIMENSIONAL_TEXTURES = Res.rl("textures/atlas/paintings.png");
	public static final ResourceLocation INFO_LOCATION = Res.rl("painting");
	private static final ResourceLocation BACK_SPRITE_LOCATION = Res.rl("back");

	private static PaintingTextureManager spriteUploader;

	public PaintingTextureManager(TextureManager textureManager) {
		super(textureManager, LOCATION_DIMENSIONAL_TEXTURES, INFO_LOCATION);
	}

	public TextureAtlasSprite get(PaintingType paintingType) {
		return this.getSprite(Objects.requireNonNull(PaintingTypeRegistry.PAINTINGS.get().getKey(paintingType)));
	}

	public TextureAtlasSprite getBackSprite() {
		return this.getSprite(BACK_SPRITE_LOCATION);
	}

	public static void initialize(RegisterClientReloadListenersEvent event) {
		spriteUploader = new PaintingTextureManager(Minecraft.getInstance().getTextureManager());
		event.registerReloadListener(spriteUploader);
	}

	public static PaintingTextureManager instance() {
		return spriteUploader;
	}
}